import { createStore } from "vuex";
import { login,status } from "../request/Home/App_resData";
import { getLyric } from "../request/ItemMusic/MusicData";
import { getRecommendMv, getMvDate, getComment } from "../request/mv/mvDate";
import {getUserDetail} from '../request/subCount/subCount'
export default createStore({
  state: {
    playList: [
      {
        al: {
          id: 0,
          name: "暂无歌曲",
          pic: 0,
          picUrl:
            "https://cube.elemecdn.com/9/c2/f0ee8a3c7c9638a54940382568c9dpng.png",
        },
        ar: [{ name: "" }],
        id: 0,
      },
    ],
    playListIndex: 0,
    isBtnShow: true,
    musicCurrentTime: 0,
    duration: 0, //歌曲总时长
    musicData: {},
    mvData: [], //mv评论现在还没写
    mvComment: [],
    mvName:[],
    lyricList: {},
    User:true, //用户登录状态
    login: {
      data: {
        profile: {
          //用户信息
          nickname: "请点击头像登录",
        },
      }
    } //token和登录数据的保存
  },
  getters: {},
  mutations: {
    upDateMusicData(state, step) {
      state.musicData = step;
    },
    upDataIsBtnShow: function (state, value) {
      state.isBtnShow = value;
    },
    updatePlayList: function (state, value) {
        state.playList = value;
    },
    upDatePlayListIndex: function (state, value) {
      if (state.playListIndex == 0) {
        state.playListIndex = 0;
      }
      state.playListIndex = value;
      state.isBtnShow = false;
    },
    upmvData: function (state, value) {
      for (let i = 0; i < value.data.length; i++) {
        state.mvName[i] = value.data[i].name
        getMvDate(value.data[i].id)
          .then((res) => {
            state.mvData[i] = res.data.data.url;
            getComment(res.data.data.id)
              .then((res) => {
                state.mvComment[i] = res.data.comments;
              })
              .catch((err) => {
                console.log(err);
              });
          })
          .catch((err) => {
            console.log(err);
          });
      }
    },
    upDataMusicCurrentTime: function (state, value) {
      state.musicCurrentTime = value;
    },
    upDataDuration: function (state, value) {
      state.duration = value;
    },
    upRecommendDate: function (state, value) {
      state.RecommendDate = value;
    }
  },
  actions: {
    getLyric: async function (context, value) {
      let res = await getLyric(value);
      this.state.lyricList = res.data.lrc;
    },
    getRecommendMv: async function (context, value) {
      let res = await getRecommendMv();
      context.commit("upmvData", res.data);
    },
    getUserDetail: async function(context,value){ //获取用户详情
      let res = await getUserDetail(value)
      console.log(11);
      return res
    },
    Login: async function (context, value) {
      let res = await login(value.phone, value.password);
      return res;
    },
    status:async function(context,value){ //检查登录状态
      let res = await status()
      return res;
    }
  }, //放异步请求的
  modules: {},
});
